/*
 *  Asteroid.cpp
 *  GLRender
 *
 *  Created by Patrick zulian on 5/4/10.
 *  Copyright 2010 University  of Lugano. All rights reserved.
 *
 */

#include "Asteroid.h"
#include "CollisionReaction.h"
#include "Physics.h"
#include "SoundEngine.h"

Asteroid::Asteroid(const Point3d &position, const Point3d &velocity0, const double mass, const double radius): WMovingObject(position, velocity0, mass, radius){

	setLife(30.0);
	setStrength(30.0);
	reaction.addReaction("SpaceShip",HARM);
	reaction.addReaction("Projectile",HARM);
	reaction.addReaction("Asteroid",IGNORE);
}

void
Asteroid::renderOn(AbstractRenderer *renderer){
	renderer->renderAsteroid(this);
}

void Asteroid::onCollision (WObject *from)
{
	switch (from->getReaction().getReaction("Asteroid")) {
		case HARM:
			Physics::getInstance()->collide(this, from);
			collided = true;
			this->life -= from->getStrength();
			if (this->life <= 0) {
				this->alive() = false;
				SoundEngine::getInstance()->play("Explosion");
			}
			break;
		case DIE:
			this->alive() = false;
			SoundEngine::getInstance()->play("Explosion");
			break;
		default:
			Physics::getInstance()->collide(this, from);
			collided = true;
			break;
	}
}
